package org.opentcs.kcvehicle.communication.kc.udp.agv.param.function.navigation;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opentcs.kcvehicle.communication.kc.common.byteutils.ByteUtils;

public class ActionSet {
  public static void main(String[] args) {
    byte[] stop = stop0x01(1, (byte) 0x01);
    System.out.println();
  }

  public static byte stop0x01 = 0x01;
  public static byte fork0x12 = 0x12;
  public static byte cancel0x03 = 0x03;

  public static byte recover0x02 = 0x02;
  public static byte cancelTask0x03 = 0x03;
  public static byte forkliftElevation0x12 = 0x12;
  public static byte trayElevation0x16 = 0x16;


  public static Integer stop0x01_paramsize = 8;
  public static Integer fork0x12_paramsize = 8;
  public static Integer cancle0x03_paramsize = 8;
  public static Integer recover0x02_paramsize = 8;
  public static Integer cancelTask0x03_paramsize = 8;
  public static Integer forkliftElevation0x12_paramsize = 8;
  public static Integer trayElevation0x16_paramsize = 4;


  public static byte[] stop0x01(Integer orderId, byte isStopImmediately) {
    ByteBuf byteBuf = Unpooled.buffer(8);
    byteBuf.writeBytes(ByteUtils.intToBytes(orderId, 1));
    byteBuf.writeByte(isStopImmediately);
    return byteBuf.array();
  }

  /**
   * high : 升降高度
   * type： 1 上升  ； 2 下降
   * command : 0：无任务
   *          1：开始任务
   *          2：暂停任务
   *          3：继续任务
   *          4：放弃任务
   * */
  public static byte[] fork0x12(Float high, byte type,byte command) {
    ByteBuf byteBuf = Unpooled.buffer(8);
    byteBuf.writeBytes(ByteUtils.floatToBytes(high));
    byteBuf.writeByte((byte)0x01);
    byteBuf.writeByte(type);
    byteBuf.writeByte(command);
    byteBuf.writeByte((byte)0x00);
    return byteBuf.array();
  }

  public static byte[] cancel0x12(Integer orderId, byte type) {
    ByteBuf byteBuf = Unpooled.buffer(8);
    byteBuf.writeBytes(ByteUtils.intToBytes(orderId, 1));
    byteBuf.writeByte(type);
    return byteBuf.array();
  }


  public static byte[] recover0x02(Integer orderId, Integer taskKey) {
    ByteBuf byteBuf = Unpooled.buffer(8);
    byteBuf.writeBytes(ByteUtils.intToBytes(orderId, 1));
    byteBuf.writeBytes(ByteUtils.intToBytes(taskKey, 1));
    return byteBuf.array();
  }

  //取消任务
  public static byte[] cancelTask0x03(Integer orderId, byte isStopImmediately) {
    ByteBuf byteBuf = Unpooled.buffer(8);
    byteBuf.writeBytes(ByteUtils.intToBytes(orderId, 1));
    byteBuf.writeByte(isStopImmediately);
    return byteBuf.array();
  }

  /**
   * desc:叉齿升降
   * 支持的命令：0xAE 0xB2
   *
   */

  public static byte[] forkliftElevation0x12(
      float lifitingHeight, byte hightMean, byte moveType, byte taskOperationType
  ) {
    ByteBuf byteBuf = Unpooled.buffer(8);
    byteBuf.writeBytes(ByteUtils.floatToBytes(lifitingHeight));
    byteBuf.writeByte(hightMean);
    byteBuf.writeByte(moveType);
    byteBuf.writeByte(taskOperationType);
    return byteBuf.array();
  }

  //托盘升降
  public static byte[] trayElevation0x16(byte palletMovementMode) {
    ByteBuf byteBuf = Unpooled.buffer(4);
    byteBuf.writeByte(palletMovementMode);
    return byteBuf.array();
  }

}
